package com.mobi.Survey.controller;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.json.JSONException;

import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.mobi.Survey.uicomponents.ControlFactory;
import com.mobi.Survey.utils.Helper;

public class SurveysJsonParser
{
	private static JsonFactory jsonFactory = new JsonFactory();

	@SuppressWarnings("deprecation")
	public final static boolean isUser(InputStream is) throws JSONException
	{
		JsonParser jParser;
		try
		{
			if (is == null)
				return false;
			if (jsonFactory == null)
				jsonFactory = new JsonFactory();
			jParser = jsonFactory.createJsonParser(is);
			return isUser(jParser);
		} catch (JsonParseException e)
		{

			e.printStackTrace();
			return false;
		} catch (IOException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		}

	}

	@SuppressWarnings("deprecation")
	public final static boolean isUser(String json) throws JSONException
	{
		JsonParser jParser = null;
		try
		{
			if (json == null)
				return false;
			if (jsonFactory == null)
				jsonFactory = new JsonFactory();

			jParser = jsonFactory.createJsonParser(json);
			return isUser(jParser);
		} catch (JsonParseException e)
		{

			e.printStackTrace();
			return false;
		} catch (IOException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
			return false;
		}

	}

	public final static boolean isUser(JsonParser jParser)
			throws JSONException, IOException
	{

		while (jParser.nextToken() != JsonToken.END_OBJECT)
		{

			String fieldname = jParser.getCurrentName();
			String tokenValue = null;
			if ("statusValue".equals(fieldname))
			{
				jParser.nextToken();

				tokenValue = jParser.getText();
				User.getInstance().setActive(Helper.toInt(tokenValue) == 1);

			} else if ("status".equals(fieldname))
			{
				jParser.nextToken();
				tokenValue = jParser.getText();
				User.getInstance().setUser(
						tokenValue.trim()
								.equalsIgnoreCase("Successfully Login"));

			} else if ("Advertisement".equals(fieldname))
			{
				jParser.nextToken();
				tokenValue = jParser.getText();
				User.getInstance().setShowAds(Helper.toInt(tokenValue) == 1);

			} else if ("Image1".equals(fieldname))
			{
				jParser.nextToken();
				tokenValue = jParser.getText();
				User.getInstance().getListImage().setUrl(tokenValue);

			} else if ("Image1Size".equals(fieldname))
			{
				jParser.nextToken();
				tokenValue = jParser.getText();
				User.getInstance().getListImage()
						.setPercentHeight(Helper.toInt(tokenValue));

			}

			else if ("Image2".equals(fieldname))
			{
				jParser.nextToken();
				tokenValue = jParser.getText();
				User.getInstance().getDetailImage().setUrl(tokenValue);

			}

			else if ("Image2Size".equals(fieldname))
			{
				jParser.nextToken();
				tokenValue = jParser.getText();
				User.getInstance().getDetailImage()
						.setPercentHeight(Helper.toInt(tokenValue));

			}

		}
		if (User.getInstance().isActive() && User.getInstance().isUser())
		{
			return true;
		}

		return false;

	}

	@SuppressWarnings("deprecation")
	public static final List<SurveyPojo> parseSurveysWithJacksonStreaming(
			String json)
	{

		JsonParser jParser = null;
		try
		{
			if (json != null)
			{
				jParser = jsonFactory.createJsonParser(json);
				return parseSurveysWithJacksonStreaming(jParser);
			}
		} catch (JsonParseException e)
		{

			e.printStackTrace();
		} catch (IOException e)
		{

			e.printStackTrace();
		}
		return new ArrayList<SurveyPojo>();

	}

	@SuppressWarnings("deprecation")
	public static final List<SurveyPojo> parseSurveysWithJacksonStreaming(
			InputStream json)
	{

		JsonParser jParser = null;
		try
		{
			if (jsonFactory == null)
				jsonFactory = new JsonFactory();
			if (json != null)
			{
				jParser = jsonFactory.createJsonParser(json);
				return parseSurveysWithJacksonStreaming(jParser);
			}
		} catch (JsonParseException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e)
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return new ArrayList<SurveyPojo>();

	}

	private static final List<SurveyPojo> parseSurveysWithJacksonStreaming(
			JsonParser jParser) throws JsonParseException, IOException
	{

		List<SurveyPojo> sps = new ArrayList<SurveyPojo>();
		final String SIZE_REGE = "\\d{1,2}(x|X)\\d{1,2}";

		String tokenValue = null;
		while (jParser.nextToken() != JsonToken.END_OBJECT)
		{

			String fieldname = jParser.getCurrentName();

			if ("status".equals(fieldname))
			{
				jParser.nextToken();
				tokenValue = jParser.getText();

				// System.out.println(tokenValue); // display mkyong

			} else if ("statusValue".equals(fieldname))
			{
				jParser.nextToken();
				tokenValue = jParser.getText();
				if (Integer.valueOf(jParser.getText()) != 1)
				{
					break;
				}
			} else if ("surveys".equals(fieldname))
			{
				tokenValue = null;
				SurveyPojo sp = null;
				SubscriptionPojo sub = null;
				List<SurveyDetailPojo> sdps = null;
				while (jParser.nextToken() != JsonToken.END_ARRAY)
				{
					fieldname = jParser.getCurrentName();
					if (jParser.getCurrentToken() == JsonToken.START_OBJECT)
					{
						sp = new SurveyPojo();
						sub = new SubscriptionPojo();

					} else if ("Button1Value".equals(fieldname))
					{
						jParser.nextToken();
						tokenValue = jParser.getText();
						sp.setTxtBtnStartSurvey(tokenValue);
						// System.out.println(tokenValue); // display mkyong

					} else if ("Button2Value".equals(fieldname))
					{
						jParser.nextToken();
						tokenValue = jParser.getText();

						sp.setTxtBtnSurveyResult(tokenValue);
						// System.out.println(tokenValue); // display mkyong

					} else if ("Button3Value".equals(fieldname))
					{
						jParser.nextToken();
						tokenValue = jParser.getText();
						sp.setTxtBtnCorrectAnswer(tokenValue);
						// System.out.println(tokenValue); // display mkyong

					} else if ("CompanyEmail".equals(fieldname))
					{
						jParser.nextToken();
						tokenValue = jParser.getText();
						sp.setSubsEmail(tokenValue);
						sub.setEmail(tokenValue);
						// System.out.println(tokenValue); // display mkyong

					} else if ("CompanyName".equals(fieldname))
					{
						jParser.nextToken();
						tokenValue = jParser.getText();
						sp.setCompanyName(tokenValue);
						// System.out.println(tokenValue); // display mkyong

					} else if ("EmailAddress".equals(fieldname))
					{
						jParser.nextToken();
						tokenValue = jParser.getText();
						sp.setContactEmail(tokenValue);
						// System.out.println(tokenValue); // display mkyong

					} else if ("FirstName".equals(fieldname))
					{
						jParser.nextToken();
						tokenValue = jParser.getText();
						sub.setfName(tokenValue);
						// System.out.println(tokenValue); // display mkyong

					} else if ("FormDescription".equals(fieldname))
					{
						jParser.nextToken();
						tokenValue = jParser.getText();
						sp.setSurveyDiscription(tokenValue);
						// System.out.println(tokenValue); // display mkyong

					} else if ("Phone".equals(fieldname))
					{
						jParser.nextToken();
						tokenValue = jParser.getText();
						sp.setPhone(tokenValue);
						// System.out.println(tokenValue); // display mkyong

					} else if ("FormId".equals(fieldname))
					{
						jParser.nextToken();
						tokenValue = jParser.getText();
						long id = Long.parseLong(tokenValue);
						if (id == 0)
							throw new RuntimeException("Invalid Survey Id");
						sp.setId(id);

						// System.out.println(tokenValue); // display mkyong

					} else if ("FormKey".equals(fieldname))
					{
						jParser.nextToken();
						tokenValue = jParser.getText();
						sp.setSurveyKey(tokenValue);
						// System.out.println(tokenValue); // display mkyong

					} else if ("iconUrl".equals(fieldname))
					{
						jParser.nextToken();
						tokenValue = jParser.getText();
						sp.setIconAddress(tokenValue);
						// System.out.println(tokenValue); // display mkyong

					} else if ("LastName".equals(fieldname))
					{
						jParser.nextToken();
						tokenValue = jParser.getText();
						sub.setlName(tokenValue);
						// System.out.println(tokeValue);

					} else if ("Mandatory".equals(fieldname))
					{
						jParser.nextToken();
						tokenValue = jParser.getText();

						// System.out.println(tokeValue);

					} else if ("Pages".equals(fieldname))
					{
						jParser.nextToken();
						tokenValue = jParser.getText();
						sp.setShowAllControls(Boolean.parseBoolean(tokenValue));
						// System.out.println(tokeValue);

					} else if ("rowCount".equals(fieldname))
					{
						jParser.nextToken();
						tokenValue = jParser.getText();
						// System.out.println(tokeValue);

					} else if ("SeqNum".equals(fieldname))
					{
						jParser.nextToken();
						tokenValue = jParser.getText();

						// System.out.println(tokeValue);

					} else if ("SubscriptionId".equals(fieldname))
					{
						jParser.nextToken();
						tokenValue = jParser.getText();
						sub.setSubsId(Long.parseLong(tokenValue));
						sp.setSubscriptionId(Long.parseLong(tokenValue));

						// System.out.println(tokeValue);

					} else if ("Website".equals(fieldname))
					{
						jParser.nextToken();
						tokenValue = jParser.getText();
						sp.setWebsite(tokenValue);
						// System.out.println(tokeValue);

					} else if ("status".equals(fieldname))
					{
						jParser.nextToken();
						tokenValue = jParser.getText();
						if (Integer.valueOf(jParser.getText()) != 1)
						{
							break;
						}

					} else if ("FontColor".equals(fieldname))
					{
						jParser.nextToken();
						tokenValue = jParser.getText();
						sp.setFontColor(tokenValue);

					} else if ("BGColor".equals(fieldname))
					{
						jParser.nextToken();
						tokenValue = jParser.getText();
						sp.setbGColor(tokenValue);

					} else if ("BGImage".equals(fieldname))
					{
						jParser.nextToken();
						tokenValue = jParser.getText();
						sp.setbGImageUrl(tokenValue);

					}

					else if ("FormData".equals(fieldname))
					{
						SurveyDetailPojo sdp = null;
						sdps = new ArrayList<SurveyDetailPojo>();
						while (jParser.nextToken() != JsonToken.END_ARRAY)
						{

							fieldname = jParser.getCurrentName();
							if (jParser.getCurrentToken() == JsonToken.START_OBJECT)
							{
								sdp = new SurveyDetailPojo();
							} else if ("ControlPara1".equals(fieldname))
							{
								jParser.nextToken();
								tokenValue = jParser.getText();
								sdp.setControlParameter(tokenValue);
								// System.out.println(tokenValue);

							} else if ("ControlResult".equals(fieldname))
							{
								jParser.nextToken();
								tokenValue = jParser.getText();
								sdp.setActualValue(tokenValue);
								// System.out.println(tokenValue);

							} else if ("ControlText".equals(fieldname))
							{
								jParser.nextToken();
								tokenValue = jParser.getText();
								sdp.setControlText(tokenValue);
								// System.out.println(tokenValue);

							} else if ("ControlType".equals(fieldname))
							{
								jParser.nextToken();
								tokenValue = jParser.getText();
								sdp.setControlType(Byte.parseByte(tokenValue));
								// System.out.println(tokenValue);

							} else if ("FormId".equals(fieldname))
							{
								jParser.nextToken();
								tokenValue = jParser.getText();
								long formId = Long.parseLong(tokenValue);

								sdp.setSurveyId(formId);
								// System.out.println(tokenValue);

							} else if ("Mandatory".equals(fieldname))
							{
								jParser.nextToken();
								tokenValue = jParser.getText();
								sdp.setMendatory(Boolean.valueOf(tokenValue));
								// System.out.println(tokenValue);

							} else if ("rowCount".equals(fieldname))
							{
								jParser.nextToken();
								tokenValue = jParser.getText();
								// System.out.println(tokenValue); //

							} else if ("SeqNum".equals(fieldname))
							{
								jParser.nextToken();
								tokenValue = jParser.getText();
								sdp.setSequanceNo(Integer.parseInt(tokenValue));
								// System.out.println(tokenValue); //

							} else if ("SubscriptionId".equals(fieldname))
							{
								jParser.nextToken();
								tokenValue = jParser.getText();
								sdp.setSubscriptionId(Long
										.parseLong(tokenValue));
								// System.out.println(tokenValue);

							} else if ("Size".equals(fieldname))
							{
								jParser.nextToken();
								tokenValue = jParser.getText();

								if (null != tokenValue && tokenValue != "null"
										&& tokenValue.length() > 0
										&& tokenValue.matches(SIZE_REGE))
								{
									String[] size = tokenValue.split("x|X");
									sdp.setPercentWidth(Helper.toFloat(size[0]));
									sdp.setPercentHeight(Helper
											.toFloat(size[1]));

								}

							} else if (jParser.getCurrentToken() == JsonToken.END_OBJECT)
							{
								if (sp.getId() == sdp.getSurveyId())
								{
									// TODO remove BackGroundImage if condition
									if (sdp.getControlType() == ControlFactory.CONTROL_IMAGE_VIEW
											&& sdp.getActualValue() == "BackGroundImage")
										continue;
									sdps.add(sdp);
								}
							}
						}

					} else if (jParser.getCurrentToken() == JsonToken.END_OBJECT)
					{
						if (sdps.size() > 0)
						{
							Collections.sort(sdps,
									new SurveyDetailPojo.SortBySequance());
							sp.setSurveyDetail(sdps);
							sp.setSubscription(sub);
							sps.add(sp);
						}
					}

				}

			}

		}

		return sps;

	}

	public static String getDummySurveysJson(int surveyCount)
	{
		StringBuilder sb = new StringBuilder(2048);
		sb.append("{").append("	\"status\": \"Survey Result\",")
				.append("	\"statusValue\": \"1\",").append("	\"surveys\": [");
		for (int i = 1; i <= surveyCount; i++)
		{
			sb.append("{		\"Button1Value\": \"Check if you can win a price!\",")
					.append("		\"Button2Value\": \"Check Survey Result of these products\",")
					.append("		\"Button3Value\": \"View Correct Price of the products\",")
					.append("		\"CompanyEmail\": \"info@mobimediasoft.com\",")
					.append("		\"CompanyName\": \"Mobi Media Soft\",")
					.append("		\"ControlType\": \"0\",")
					.append("		\"EmailAddress\": \"mobimediausa@gmail.com\",")
					.append("		\"FirstName\": \"Shehzad1\",")
					.append("		\"FormDescription\": \"Price is Right\",")
					.append("		\"Phone\": \"513-706-2031\",")
					.append("		\"FormId\": \"" + i + "\",")
					.append("		\"FormKey\": \"PRICE01\",")
					.append("		\"iconUrl\": \"http://test.readymademobileapps.com/img/rmma_icon.jpg\",")
					.append("		\"LastName\": \"Jamil\",")
					.append("		\"Mandatory\": \"false\",")
					.append("		\"Pages\": \"false\",")
					.append("		\"rowCount\": \"1\",")
					.append("		\"SeqNum\": \"0\",")
					.append("		\"SubscriptionId\": \"4\",")
					.append("		\"Website\": \"www.mobimediasoft.com\",")
					.append("		\"status\": \"1\",")
					.append("		\"FormData\": [{")
					.append("			\"ControlPara1\": \"\",")
					.append("			\"ControlResult\": \"\",")
					.append("			\"ControlText\": \"Welcome to Price is Right. There is a chance to win a prize when you correctly answer prices of below products. Let us start this fun!\",")
					.append("			\"ControlType\": \"0\",")
					.append("			\"FormId\": \"24\",")
					.append("			\"Mandatory\": \"false\",")
					.append("			\"Pages\": \"false\",")
					.append("			\"rowCount\": \"0\",")
					.append("			\"SeqNum\": \"159\",")
					.append("			\"SubscriptionId\": \"4\"")
					.append("		},")
					.append("		{")
					.append("			\"ControlPara1\": \"http://test.readymademobileapps.com/img/black_background_tile.jpg\",")
					.append("			\"ControlResult\": \"BackGroundImage\",")
					.append("			\"ControlText\": \"Welcome to Price is Right. There is a chance to win a prize when you correctly answer prices of below products. Let us start this fun!\",")
					.append("			\"ControlType\": \"6\",")
					.append("			\"FormId\": \"" + i + "\",")
					.append("			\"Mandatory\": \"false\",")
					.append("			\"Pages\": \"false\",")
					.append("			\"rowCount\": \"0\",")
					.append("			\"SeqNum\": \"160\",")
					.append("			\"SubscriptionId\": \"4\"")
					.append("		},")
					.append("		{")
					.append("			\"ControlPara1\": \"http://www.ftcinternational.com/images/ice%20cream%20product%20development.jpg\",")
					.append("			\"ControlResult\": \"photo\",")
					.append("			\"ControlText\": \"Do you know the price of this ice cream cake?\",")
					.append("			\"ControlType\": \"6\",")
					.append("			\"FormId\": \"" + i + "\",")
					.append("			\"Mandatory\": \"false\",")
					.append("			\"Pages\": \"false\",")
					.append("			\"rowCount\": \"0\",")
					.append("			\"SeqNum\": \"161\",")
					.append("			\"SubscriptionId\": \"4\"")
					.append("		},")
					.append("		{")
					.append("			\"ControlPara1\": \"$15|$25|$28|$30|$35\",")
					.append("			\"ControlResult\": \"$25\",")
					.append("			\"ControlText\": \"In your opinion the price of this ice cream cake is\",")
					.append("			\"ControlType\": \"2\",")
					.append("			\"FormId\": \"" + i + "\",")
					.append("			\"Mandatory\": \"true\",")
					.append("			\"Pages\": \"false\",")
					.append("			\"rowCount\": \"0\",")
					.append("			\"SeqNum\": \"162\",")
					.append("			\"SubscriptionId\": \"4\"")
					.append("		},")
					.append("		{")
					.append("			\"ControlPara1\": \"http://3.bp.blogspot.com/_23c84B1qRxE/TQNIDA_-BzI/AAAAAAAAAHc/bGL_12h0UY0/s400/ipod-nano-product-red.jpg\",")
					.append("			\"ControlResult\": \"photo\",")
					.append("			\"ControlText\": \"Do you know the price of this iPod\",")
					.append("			\"ControlType\": \"6\",")
					.append("			\"FormId\": \"" + i + "\",")
					.append("			\"Mandatory\": \"false\",")
					.append("			\"Pages\": \"false\",")
					.append("			\"rowCount\": \"0\",")
					.append("			\"SeqNum\": \"163\",")
					.append("			\"SubscriptionId\": \"4\"")
					.append("		},")
					.append("		{")
					.append("			\"ControlPara1\": \"$99|$85|$78|$67|$65\",")
					.append("			\"ControlResult\": \"$65\",")
					.append("			\"ControlText\": \"In your opinion the price of this iPod is\",")
					.append("			\"ControlType\": \"4\",")
					.append("			\"FormId\": \"" + i + "\",")
					.append("			\"Mandatory\": \"true\",")
					.append("			\"Pages\": \"false\",")
					.append("			\"rowCount\": \"0\",")
					.append("			\"SeqNum\": \"164\",")
					.append("			\"SubscriptionId\": \"4\"")
					.append("		},")
					.append("		{")
					.append("			\"ControlPara1\": \"http://styleandbeauty.cult2.net/wp-content/uploads/2011/08/maccosmetics.jpg\",")
					.append("			\"ControlResult\": \"photo\",")
					.append("			\"ControlText\": \"Do you know the price of this cosmetic set?\",")
					.append("			\"ControlType\": \"6\",")
					.append("			\"FormId\": \"" + i + "\",")
					.append("			\"Mandatory\": \"false\",")
					.append("			\"Pages\": \"false\",")
					.append("			\"rowCount\": \"0\",")
					.append("			\"SeqNum\": \"165\",")
					.append("			\"SubscriptionId\": \"4\"")
					.append("		},")
					.append("		{")
					.append("			\"ControlPara1\": \"$115|$125|$128|$130|$135\",")
					.append("			\"ControlResult\": \"$130\",")
					.append("			\"ControlText\": \"In your opinion the price of this cosmetic set is\",")
					.append("			\"ControlType\": \"2\",")
					.append("			\"FormId\": \"" + i + "\",")
					.append("			\"Mandatory\": \"true\",")
					.append("			\"Pages\": \"false\",")
					.append("			\"rowCount\": \"0\",")
					.append("			\"SeqNum\": \"166\",")
					.append("			\"SubscriptionId\": \"4\"")
					.append("		},")
					.append("		{")
					.append("			\"ControlPara1\": \"http://www.youtube.com/watch?v=mcQrX_FH_fQ\",")
					.append("			\"ControlResult\": \"youtube\",")
					.append("			\"ControlText\": \"Do you know the price of this IT Cosmetics Vitality Anti-Aging 5 Piece Collection?\",")
					.append("			\"ControlType\": \"7\",")
					.append("			\"FormId\": \"" + i + "\",")
					.append("			\"Mandatory\": \"false\",")
					.append("			\"Pages\": \"false\",")
					.append("			\"rowCount\": \"0\",")
					.append("			\"SeqNum\": \"167\",")
					.append("			\"SubscriptionId\": \"4\"")
					.append("		},")
					.append("		{")
					.append("			\"ControlPara1\": \"$99|$85|$78|$67|$65\",")
					.append("			\"ControlResult\": \"$78\",")
					.append("			\"ControlText\": \"In your opinion the price of this IT Cosmetics Vitality Anti-Aging 5 Piece Collection is\",")
					.append("			\"ControlType\": \"4\",")
					.append("			\"FormId\": \"" + i + "\",")
					.append("			\"Mandatory\": \"true\",")
					.append("			\"Pages\": \"false\",")
					.append("			\"rowCount\": \"0\",")
					.append("			\"SeqNum\": \"168\",")
					.append("			\"SubscriptionId\": \"4\"")
					.append("		},")
					.append("		{")
					.append("			\"ControlPara1\": \"http://www.lgnewsroom.com/resource_product/post/99/%ED%81%AC%EA%B8%B0%EB%B3%80%ED%99%98_Product_Images_BIT_LuV300B_BLUE_M2.gif\",")
					.append("			\"ControlResult\": \"photo\",")
					.append("			\"ControlText\": \"Do you know the price of this vacuum cleaner?\",")
					.append("			\"ControlType\": \"6\",")
					.append("			\"FormId\": \"" + i + "\",")
					.append("			\"Mandatory\": \"false\",")
					.append("			\"Pages\": \"false\",")
					.append("			\"rowCount\": \"0\",")
					.append("			\"SeqNum\": \"169\",")
					.append("			\"SubscriptionId\": \"4\"")
					.append("		},")
					.append("		{")
					.append("			\"ControlPara1\": \"$115|$125|$128|$130|$135\",")
					.append("			\"ControlResult\": \"$128\",")
					.append("			\"ControlText\": \"In your opinion the price of this vacuum cleaner is\",")
					.append("			\"ControlType\": \"2\",")
					.append("			\"FormId\": \"" + i + "\",")
					.append("			\"Mandatory\": \"true\",")
					.append("			\"Pages\": \"false\",")
					.append("			\"rowCount\": \"0\",")
					.append("			\"SeqNum\": \"170\",")
					.append("			\"SubscriptionId\": \"4\"")
					.append("		},")
					.append("		{")
					.append("			\"ControlPara1\": \"http://www.youtube.com/watch?v=2tlky8l4Dac\",")
					.append("			\"ControlResult\": \"youtube\",")
					.append("			\"ControlText\": \"Do you know the price of this vacuum cleaner?\",")
					.append("			\"ControlType\": \"7\",")
					.append("			\"FormId\": \"" + i + "\",")
					.append("			\"Mandatory\": \"false\",")
					.append("			\"Pages\": \"false\",")
					.append("			\"rowCount\": \"0\",")
					.append("			\"SeqNum\": \"171\",")
					.append("			\"SubscriptionId\": \"4\"")
					.append("		},")
					.append("		{")
					.append("			\"ControlPara1\": \"$215|$225|$228|$230|$235\",")
					.append("			\"ControlResult\": \"$215\",")
					.append("			\"ControlText\": \"In your opinion the price of this vacuum cleaner is\",")
					.append("			\"ControlType\": \"4\",")
					.append("			\"FormId\": \"" + i + "\",")
					.append("			\"Mandatory\": \"true\",")
					.append("			\"Pages\": \"false\",")
					.append("			\"rowCount\": \"0\",")
					.append("			\"SeqNum\": \"172\",")
					.append("			\"SubscriptionId\": \"4\"")
					.append("		},")
					.append("		{")
					.append("			\"ControlPara1\": \"textEmailAddress\",")
					.append("			\"ControlResult\": \"\",")
					.append("			\"ControlText\": \"Enter your mail address to receive your prize\",")
					.append("			\"ControlType\": \"1\",")
					.append("			\"FormId\": \"" + i + "\",")
					.append("			\"Mandatory\": \"true\",")
					.append("			\"Pages\": \"false\",")
					.append("			\"rowCount\": \"0\",")
					.append("			\"SeqNum\": \"173\",")
					.append("			\"SubscriptionId\": \"4\"").append("		}]")
					.append("	}");
			if (i < surveyCount)
				sb.append(",");
		}
		sb.append("]}");

		return sb.toString();
	}

}